/**
 * 主屏幕
 * @authors yangchaojun (YYChildren@gmail.com)
 * @date    2018-12-14 18:20:21
 * @version 0.0.1
 */

import {ui} from '../ui/layaMaxUI';
import LoginView from './Login/LoginView';
import GameInfo from '../model/GameInfo';
import { GameStatusEnum } from '../model/Enums';
import GamePlayView from './GamePlay/GamePlayView';
import MatterManager from '../managers/MatterManager';
import SteeringWheelView from './SteeringWheel/SteeringWheelView';
import GameView from './GamePlay/GameView';
import GameOverView from './GameOver/GameOverView';

export default class MainScreen extends ui.MainScreenUI{

    static instance: MainScreen;
    private loginView: LoginView = new LoginView();

    public gamePlayView: GamePlayView = new GamePlayView();

    private steeringWheelView: SteeringWheelView = new SteeringWheelView();

    public gameView : GameView = new GameView();

    public gameOverView: GameOverView = new GameOverView();

    constructor() {
        super();
        MainScreen.instance = this;
    }

    public onAwake() {
        Laya.stage.on(Laya.Event.RESIZE, this, this.onResize);
        this.loadSences();
    }


    private loadSences() {
    }

    // TODO
    private onResize() {
    }

    public onEnable() {
        this.uiLayer.addChild(this.loginView);
        MatterManager.instance.init(this.gamePlayView);
        // MatterManager.instance.sprite = this.gamePlayView;

        this.initEvent();
    }
    

    public initEvent() {
        GameInfo.instance.on("gameStatus", this, () => {
            switch (GameInfo.instance.gameStatus) {
                case GameStatusEnum.Gaming:
                    this.uiLayer.addChild(this.gamePlayView);
                    this.uiLayer.addChild(this.steeringWheelView);
                    break;
                case GameStatusEnum.GameOver:
                    this.uiLayer.addChild(this.gameOverView);
                default:
                    break;
            }
        })
    }

    public onDisable() {
        
    }
    
}